/* 封装文章接口 */

import axios from '@/utils/request'

/**
 * 获取文章列表数据
 * @param {*} channelId 频道id
 * @param {*} timestamp 时间戳
 * @returns
 */
export function getArtilceList(channelId, timestamp) {
  return axios({
    url: '/v1_0/articles',
    params: {
      channel_id: channelId,
      timestamp
    }
  })
}

/**
 * 对文章不喜欢
 *
 * @export
 * @param {*} target 不喜欢的文章id
 * @return {*}
 */
export function articleDisLike(target) {
  return axios({
    method: 'POST',
    url: '/v1_0/article/dislikes',
    data: {
      target
    }
  })
}

/**
 * 举报文章
 *
 * @export
 * @param {*} target 文章id
 * @param {*} type  举报类型
 * @return {*}
 */
export function articleReport(target, type) {
  return axios({
    method: 'POST',
    url: '/v1_0/article/reports',
    data: { target, type }
  })
}

/**
 * 获取新闻详情
 *
 * @export
 * @param {*} artId 文章Id
 * @return {*}
 */
export function getArtilceDetail(artId) {
  return axios({ url: '/v1_0/articles/' + artId })
}

/**
 * 关注作者
 *
 * @export
 * @param {*} target 关注的用户的id
 * @return {*}
 */
export function followUser(target) {
  return axios({
    method: 'POST',
    url: '/v1_0/user/followings',
    data: {
      target
    }
  })
}

/**
 * 取消关注作者
 *
 * @export
 * @param {*} target 关注的用户的id
 * @return {*}
 */
export function unFollowUser(target) {
  return axios({
    method: 'DELETE',
    url: '/v1_0/user/followings/' + target
  })
}

/**
 * 取消点赞
 * @param {*} id 文章编号
 */
export const deleteLike = id => {
  return axios({
    method: 'delete',
    url: '/v1_0/article/likings/' + id
  })
}

/**
 * 添加点赞
 * @param {*} id 文章编号
 */
export const addLike = id => {
  return axios({
    method: 'post',
    url: '/v1_0/article/likings',
    data: {
      target: id
    }
  })
}

/**
 * 取消不喜欢
 * @param {*} id 文章编号
 */
export const deleteDisLike = id => {
  return axios({
    method: 'delete',
    url: '/v1_0/article/dislikes/' + id
  })
}

/**
 * 添加不喜欢
 * @param {*} id 文章编号
 */
export const addDisLike = id => {
  return axios({
    method: 'post',
    url: '/v1_0/article/dislikes',
    data: {
      target: id
    }
  })
}

/**
 * 获取对文章的评论
 *
 * @export
 * @param {*} source 文章id
 * @param {*} offset 偏移量 获取第几页数据
 * @return {*}
 */
export function getArticleCommon(source, offset) {
  return axios({
    url: '/v1_0/comments',
    params: {
      type: 'a',
      source,
      offset,
      limit: 10
    }
  })
}

/**
 * 对文章进行发表评论
 *
 * @export
 * @param {*} target 文章id
 * @param {*} content 评论内容
 * @return {*}
 */
export function addArticleCommon(target, content) {
  return axios({
    url: '/v1_0/comments',
    method: 'post',
    data: {
      target,
      content
    }
  })
}

/**
 * 对评论进行点赞
 *
 * @export
 * @param {*} target 评论id
 * @return {*}
 */
export function likeCommon(target) {
  return axios({
    url: '/v1_0/comment/likings',
    method: 'post',
    data: {
      target
    }
  })
}

/**
 * 对评论进行取消点赞
 *
 * @export
 * @param {*} target 评论id
 * @return {*}
 */
export function unLikeCommon(target) {
  return axios({
    url: '/v1_0/comment/likings/' + target,
    method: 'DELETE'
  })
}

/**
 * 获取评论回复的评论
 *
 * @export
 * @param {*} source 评论id
 * @param {*} offset 偏移量 获取第几页数据
 * @return {*}
 */
export function getCommonToCommon(source, offset) {
  return axios({
    url: '/v1_0/comments',
    params: {
      type: 'c',
      source,
      offset,
      limit: 10
    }
  })
}

/**
 * 对评论进行发表评论
 *
 * @export
 * @param {*} artId 文章id
 * @param {*} target 评论id
 * @param {*} content 评论内容
 * @return {*}
 */
export function addCommonToCommon(artId, target, content) {
  return axios({
    url: '/v1_0/comments',
    method: 'post',
    data: {
      art_id: artId,
      target,
      content
    }
  })
}
